package com.cy.springcloudalibaba.controllers;

import com.cy.springcloudalibaba.models.Product;
import com.cy.springcloudalibaba.services.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 产品
 * @ClassName: ProductController
 * @Author: chenyu
 * @Date: 2025/2/6 14:21
 */
@Slf4j
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    @PostMapping("/product/reduceStock")
    public Product reduceStock(@RequestParam("productId") Integer productId, @RequestParam("amount") Integer amount) throws Exception {
        log.info("[reduceStock] 收到减少库存请求，商品：{}，数量：{}", productId, amount);
        return productService.reduceStock(productId, amount);
    }
}
